<template>
	<div class="content">
		<div class="clear">
			<Form inline class="fl">
				<Input type="text" placeholder="请输入ID" class="w200 m-r10" v-model="userId" />
				<Input type="text" placeholder="请输入收益人ID" class="w200 m-r10" v-model="userId" />
				<DatePicker type="daterange" split-panels placeholder="请选择时间段" class="w200 m-r10" format="yyyy-MM-dd HH:mm:ss" @on-change="getTime">
				</DatePicker>
				<Button type="primary" @click="query">查询</Button>
			</Form>
		</div>
		<fieldset>
			<legend>汇总</legend>
			<div>
				<table>
					<tbody>
						<tr>
							<td>累积积分收益：
								<span class="blue">{{ huizong.goBtcIncomeSum == null ? 0 : huizong.goBtcIncomeSum }}</span>
							</td>
						</tr>
					</tbody>
				</table>
			</div>
		</fieldset>
		<Button class="daochu" type="primary" size="large" @click="exportData">
            <Icon type="ios-download-outline"></Icon> 导出</Button>
		<Table stripe :columns="columns1" :data="btcList" ref="table" v-show="btc"></Table>
		<Page :total="info" show-elevator :page-size="pageSize" show-total @on-change="changepage" v-show="fenye"></Page>
		<Page :total="info1" show-elevator :page-size="pageSize" show-total @on-change="changepage1" v-show="fenye1"></Page>
	</div>
</template>
<script>
	export default {
		data() {
			return {
				btc: true,
				eth: false,
				fenye: true,
				fenye1: false,
				bizhong: '1',
				userId: '',
				btcList: [],
				ethList: [],
				huizong: {},
				dataValue: [], // 时间段值
				// // 分页
				info: null, // 总条数
				info1: null, // 总条数
				page: 1, // 页数
				pageSize: 20, // 每页多少条
				columns1: [{
						title: '节点个人ID',
						align: 'center',
						key: 'uuid'
					},
					{
						title: '节点用户手机号码',
						align: 'center',
						key: 'num',
						render: (h, params) => {
							return h('div', params.row.num == null ? '#' : params.row.num)
						}
					},
					{
						title: '收益人个人ID',
						align: 'center',
						key: 'sumProfits'
					},
					{
						title: '收益人个人手机号码',
						align: 'center',
						key: 'sumProfits',
						render: (h, params) => {
							return h('div', params.row.sumProfits == null ? '#' : params.row.sumProfits)
						}
					},
					{
						title: '推荐收益比例',
						align: 'center',
						key: 'sumProfits'
					},
					{
						title: '收益数量',
						align: 'center',
						key: 'sumProfits'
					},
					{
						title: '收益时间',
						align: 'center',
						key: 'incomeTime',
						sortable: true
					}
				]
			}
		},
		methods: {
			exportData() {
				this.$refs.table.exportCsv({
					filename: 'BTC量化宝收益'
				})
				this.$refs.table1.exportCsv({
					filename: 'ETH量化宝收益'
				})
			},
			// 处理时间段时间格式
			getTime(daterange) {
				this.dataValue = daterange
			},
			// 获取BTC表格数据
			getBList() {
				let token = localStorage.getItem('mytoken')
				let params = this.qs.stringify({
					typeId: 2,
					pn: this.page,
					pageSize: this.pageSize
				})
				this.axios.post('statistical/goIncomeDetail', params, {
					headers: {
						Authorization: 'bearer ' + token
					}
				}).then(res => {
					// console.log(res)
					if(res.data.code == 8008) {
						this.btcList = res.data.data.data
						this.info = res.data.data.integer
					} else if(res.data.code == 5501) {
						this.$Message.info(res.data.message)
						localStorage.removeItem('mytoken')
						this.$router.push({
							name: 'login'
						})
					}
				})
			},
			// 获取eth表格数据
			getEList() {
				let token = localStorage.getItem('mytoken')
				let params = this.qs.stringify({
					typeId: 1,
					pn: this.page,
					pageSize: this.pageSize
				})
				this.axios.post('statistical/goIncomeDetail', params, {
					headers: {
						Authorization: 'bearer ' + token
					}
				}).then(res => {
					// console.log(res)
					if(res.data.code == 8008) {
						this.ethList = res.data.data.data
						this.info1 = res.data.data.integer
					} else if(res.data.code == 5501) {
						this.$Message.info(res.data.message)
						localStorage.removeItem('mytoken')
						this.$router.push({
							name: 'login'
						})
					}
				})
			},
			// 汇总
			getHuizong() {
				let token = localStorage.getItem('mytoken')

				this.axios.get('statistical/goIncomeSum', {
					headers: {
						Authorization: 'bearer ' + token
					}
				}).then(res => {
					// console.log(res)
					if(res.data.code == 8008) {
						this.huizong = res.data.data.data
					} else if(res.data.code == 5501) {
						this.$Message.info(res.data.message)
						localStorage.removeItem('mytoken')
						this.$router.push({
							name: 'login'
						})
					}
				})
			},
			// 查询
			query() {
				// console.log(this.bizhong)
				if(this.bizhong == 2) {
					this.btc = false
					this.eth = true
					this.fenye = false
					this.fenye1 = true
					if((this.dataValue == undefined || this.dataValue[0] == '' || this.dataValue.length == 0) && this.userId == '') {
						this.pageSize = 20
						this.getEList()
						return
					}
					this.pageSize = 100
					let token = localStorage.getItem('mytoken')
					let params = this.qs.stringify({
						typeId: 1,
						uuid: this.userId,
						pn: this.page,
						pageSize: this.pageSize,
						startTime: this.dataValue[0] == '' ? '2000-12-30 00:00:00' : this.dataValue[0],
						endTime: this.dataValue[1] == '' ? '2200-12-30 00:00:00' : this.dataValue[1]
					})
					this.axios.post('statistical/goIncomeDetail', params, {
						headers: {
							Authorization: 'bearer ' + token
						}
					}).then(res => {
						// console.log(res)
						if(res.data.code == 8008) {
							this.ethList = res.data.data.data
							this.info1 = this.ethList.length
							this.$Message.info(res.data.message)
						} else if(res.data.code == 4004) {
							this.$Message.info(res.data.message)
							this.ethList = []
							this.info1 = 0
						} else if(res.data.code == 5501) {
							this.$Message.info(res.data.message)
							localStorage.removeItem('mytoken')
							this.$router.push({
								name: 'login'
							})
						}
					})
				} else if(this.bizhong == 1) {
					this.btc = true
					this.eth = false
					this.fenye = true
					this.fenye1 = false
					if((this.dataValue == undefined || this.dataValue[0] == '' || this.dataValue.length == 0) && this.userId == '') {
						this.pageSize = 20
						this.getBList()
						return
					}
					this.pageSize = 100
					let token = localStorage.getItem('mytoken')
					let params = this.qs.stringify({
						typeId: 2,
						uuid: this.userId,
						pn: this.page,
						pageSize: this.pageSize,
						startTime: this.dataValue[0] == '' ? '2000-12-30 00:00:00' : this.dataValue[0],
						endTime: this.dataValue[1] == '' ? '2200-12-30 00:00:00' : this.dataValue[1]
					})
					this.axios.post('statistical/goIncomeDetail', params, {
						headers: {
							Authorization: 'bearer ' + token
						}
					}).then(res => {
						// console.log(res)
						if(res.data.code == 8008) {
							this.btcList = res.data.data.data
							this.info = this.btcList.length
							this.$Message.info(res.data.message)
						} else if(res.data.code == 4004) {
							this.$Message.info(res.data.message)
							this.btcList = []
							this.info = 0
						} else if(res.data.code == 5501) {
							this.$Message.info(res.data.message)
							localStorage.removeItem('mytoken')
							this.$router.push({
								name: 'login'
							})
						}
					})
				}
			},
			// 分页
			changepage(page) {
				this.page = page
				let token = localStorage.getItem('mytoken')
				let params = this.qs.stringify({
					typeId: 2,
					pn: page,
					pageSize: this.pageSize
				})
				// console.log(params)
				this.axios.post('statistical/goIncomeDetail', params, {
					headers: {
						Authorization: 'bearer ' + token
					}
				}).then(res => {
					if(res.data.code == 8008) {
						this.btcList = res.data.data.data
					} else if(res.data.code == 5501) {
						this.$Message.info(res.data.message)
						localStorage.removeItem('mytoken')
						this.$router.push({
							name: 'login'
						})
					}
				})
			},
			// 分页
			changepage1(page) {
				this.page = page
				let token = localStorage.getItem('mytoken')
				let params = this.qs.stringify({
					typeId: 1,
					pn: page,
					pageSize: this.pageSize
				})
				// console.log(params)
				this.axios.post('statistical/goIncomeDetail', params, {
					headers: {
						Authorization: 'bearer ' + token
					}
				}).then(res => {
					if(res.data.code == 8008) {
						this.ethList = res.data.data.data
					} else if(res.data.code == 5501) {
						this.$Message.info(res.data.message)
						localStorage.removeItem('mytoken')
						this.$router.push({
							name: 'login'
						})
					}
				})
			}
		},
		created() {
			this.getBList()
			setTimeout(() => {
				this.getEList()
			}, 500)
			this.getHuizong()
		},
		mounted() {
			this.$Message.config({
				top: 250
			})
		}
	}
</script>